﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

namespace Ping_Bing
{
    class Program
    {
        static bool flag;
        static int a = 0;
        public static void Main()
        {
            Run();
        }

        public static void Run()
        {
            FileSystemWatcher watcher = new FileSystemWatcher();
            watcher.Path = "D:\\test";
            watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
               | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            watcher.Filter = "*.txt";

            watcher.Changed += new FileSystemEventHandler(OnChanged);

            watcher.EnableRaisingEvents = true;

            Console.WriteLine("Press \'q\' to quit the sample.");
            while (Console.Read() != 'q') ;
        }

        private static void OnChanged(object source, FileSystemEventArgs e)
        {
            if (flag == true)
                flag = false;
            else
                flag = true;
            ++a;
            if (e.ChangeType == WatcherChangeTypes.Changed && flag == true)
            {
                Console.WriteLine("change");
                DealPingBing();
            }
        }
        private static void DealPingBing()
        {

        }
    }
}
